package com.rybbaby.tss.front.tssPertainRelation.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssPertainRelation.dao.ITssPertainRelationDao;
import com.rybbaby.tss.front.tssPertainRelation.entity.TssPertainRelation;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description 所属关系数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-14 上午10:34:49
 */
@Repository
public class TssPertainRelationDaoImp extends GenericDao<TssPertainRelation> implements ITssPertainRelationDao {

    /**
     * 根据客户id查询亲属所属关系
     *
     * @param studentId
     * @return
     */
    @Override
    public List<TssPertainRelation> findBySql(String studentId) {
        return this.findByHql("from TssPertainRelation where studentId=?",new String[]{studentId});
    }

    /**
     * 添加亲属信息
     * 杨然
     * @Param patriarch
     * */
    @Override
    public void saveImport(TssPertainRelation patriarch) {
        super.save(patriarch);
    }

    @Override
    public List<TssPertainRelation> findByPhone(String phone,String adminUserId) throws Exception{
        String sql = "SELECT\n" +
                "\t*\n" +
                "FROM\n" +
                "tss_student \n" +
                "WHERE tss_student.contactPhone = '"+phone+"'\n" +
                "AND tss_student.adminUserId = '"+adminUserId+"'\n";
        return super.findListBySql(sql, TssPertainRelation.class, null);
    }


    /**
     * 验证父母信息是否重复
     * 杨然
     * */
    @Override
    public List<TssPertainRelation> validationParentsMessage(String motherName, String motherPhone) {
        String sql = "select * from tss_pertain_relation a where a.patriarchName in('"+motherName+"') or a.contactPhone in('"+motherPhone+"')";

        try {
            List<TssPertainRelation> listBySql = super.findListBySql(sql, TssPertainRelation.class, null);
            if (!listBySql.isEmpty()){
                return listBySql;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
